from hw5 import *

M = Mat(({0, 1, 2}, {0, 1, 2}), {(0, 1): one, (1, 2): 0, (0, 0): 0, (2, 0): 0, (1, 0): one, (2, 2): one, (0, 2): 0, (2, 1): 0, (1, 1): 0})

I5 = [[one]+[0]*4, [0,one,0,0,0], [0,0,one,0,0], [0,0,0,one,0], [0,0,0,0,one]]
M5 = Mat(({0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}), {(1, 2): 0, (3, 2): 0, (0, 0): one, (3, 0): 0, (0, 4): 0, (1, 4): 0, (1, 3): 0, (2, 3): 0, (2, 1): 0, (2, 4): 0, (4, 2): 0, (1, 0): 0, (0, 3): 0, (4, 0): 0, (0, 1): 0, (3, 3): one, (4, 1): 0, (3, 1): 0, (4, 4): one, (0, 2): 0, (2, 0): 0, (4, 3): 0, (2, 2): one, (3, 4): 0, (1, 1): one})

print(Mat(({0, 1, 2}, {0, 1, 2}), {(0, 1): one, (2, 0): 0, (0, 0): 0, (2, 2): one, (1, 0): one, (1, 2): 0, (1, 1): 0, (2, 1): 0, (0, 2): 0}))

def inverse(M):
    eye = identity(M.D[0], one)
    eye = mat2coldict(eye)
    col_ = {}
    for label, col in zip(M.D[0], eye.values()):
         col_[label] = solve(M, col)
    print(col_)
    return coldict2mat(col_)

print(inverse(M5))
#print(inverse(M))



